const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = {
  mode: "development", // 开发模式
  entry: "./src/index.ts", // 入口文件
  devServer: {
    open: true, // 是否自动打开浏览器
  },
  resolve: {
    extensions: [".ts", ".js"], // 注意：这里至少要指定两个扩展名，一个是不行的！
  },
  output: {
    filename: "index.js", // 输出文件
    path: path.resolve(__dirname, "dist"), // 输出目录
    clean: true, // 打包前先清理输出目录
  },
  module: {
    rules: [
      { test: /\.ts$/, use: ["ts-loader"] },
      { test: /\.(png|jpg|jpeg|svg|gif|bmp)$/i, type: "asset/resource" },
    ],
  },
  plugins: [
    new CopyWebpackPlugin({
      patterns: [
        { from: "public" }, // 复制"public"文件夹里所有文件到"dist"文件夹
      ],
    }),
  ],
  cache: { type: "filesystem" },
  watchOptions: { ignored: /node_modules/, poll: 1000 },
};
